import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },

  {
    path: '/frame/dashboard',
    name: 'info-all',
    component: () => import('@/views/attendance/info'),
    hidden: true
  },
  {
    path: '/frame/dashboard2',
    component: () => import('@/views/dashboard/index'),
    hidden: true
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'Profile', icon: 'user', noCache: true }
      }
    ]
  },
  {
    path: '/frame/attendance/summary',
    title: '考勤信息管理-考勤信息汇总',
    component: () => import('@/views/attendance/summary'),
    hidden: true
  },
  {
    path: '/frame/attendance/info-all',
    title: '考勤信息管理-考勤信息(全量)',
    name: 'info-all',
    component: () => import('@/views/attendance/info'),
    hidden: true
  },
  {
    path: '/frame/attendance/info-dept',
    title: '考勤信息管理-考勤信息(部门)',
    name: 'info-dept',
    component: () => import('@/views/attendance/info'),
    hidden: true
  },
  {
    path: '/frame/attendance/info-person',
    title: '考勤信息管理-考勤信息(个人)',
    name: 'info-person',
    component: () => import('@/views/attendance/info'),
    hidden: true
  },
  {
    path: '/frame/attendance/appeal',
    title: '考勤信息管理-考勤申诉',
    component: () => import('@/views/attendance/appeal'),
    hidden: true
  },
  {
    path: '/frame/leave/leave-all',
    name: 'leave-all',
    title: '请假单管理-请假单(全量)',
    component: () => import('@/views/attendance/leave'),
    hidden: true
  },
  {
    path: '/frame/leave/leave-dept',
    title: '请假单管理-请假单(部门)',
    name: 'leave-dept',
    component: () => import('@/views/attendance/leave'),
    hidden: true
  },
  {
    path: '/frame/leave/leave-person',
    name: 'leave-person',
    title: '请假单管理-请假单(个人)',
    component: () => import('@/views/attendance/leave'),
    hidden: true
  },
  {
    path: '/frame/travel/travel-all',
    title: '外出管理-出差申请单(全量)',
    name: 'travel-all',
    component: () => import('@/views/attendance/travel'),
    hidden: true
  },
  {
    path: '/frame/travel/travel-dept',
    title: '外出管理-出差申请单(部门)',
    name: 'travel-dept',
    component: () => import('@/views/attendance/travel'),
    hidden: true
  },
  {
    path: '/frame/travel/travel-person',
    title: '外出管理-出差申请单(个人)',
    name: 'travel-person',
    component: () => import('@/views/attendance/travel'),
    hidden: true
  },
  {
    path: '/frame/travel/travel-change',
    title: '外出管理-出差变更',
    component: () => import('@/views/attendance/travel-change'),
    hidden: true
  },
  {
    path: '/frame/holiday/holidaylaws',
    title: '排班管理-假期排班',
    component: () => import('@/views/attendance/holidaylaws'),
    hidden: true
  },
  {
    path: '/frame/approval/approval-travel',
    name: 'approvalTravel',
    title: '因事外出审批',
    component: () => import('@/views/attendance/approval/approval-travel'),
    hidden: true
  },
  {
    path: '/frame/approval/approval-appeal',
    name: 'approvalAppeal',
    title: '考勤申诉审批',
    component: () => import('@/views/attendance/approval/approval-appeal'),
    hidden: true
  },
  {
    path: '/frame/approval/approval-leave',
    name: 'approvalLeave',
    title: '请假单审批',
    component: () => import('@/views/attendance/approval/approval-leave'),
    hidden: true
  },
  {
    path: '/frame/portal/leave-request',
    name: 'leave-request',
    title: '起草请假单申请',
    component: () => import('@/views/attendance/components/single/leave-request'),
    hidden: true
  },
  {
    path: '/frame/portal/travel-request',
    name: 'travel-request',
    title: '起草因公外出申请',
    component: () => import('@/views/attendance/components/single/travel-request'),
    hidden: true
  }

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {

    path: '/attendance',
    component: Layout,
    redirect: '/attendance',
    name: 'Attendance',
    meta: {
      title: '考勤管理',
      icon: 'attendance2'
    },
    children: [
      {
        path: 'info-all',
        component: () => import('@/views/attendance/info'),
        name: 'info-all',
        meta: { title: '考勤信息（全量）' }
      },
      {
        path: 'info-dept',
        component: () => import('@/views/attendance/info'),
        name: 'info-dept',
        meta: { title: '考勤信息（部门）' }
      },
      {
        path: 'info-person',
        component: () => import('@/views/attendance/info'),
        name: 'info-person',
        meta: { title: '考勤信息（个人）' }
      },
      {
        path: 'appeal',
        component: () => import('@/views/attendance/appeal'),
        name: 'Appeal',
        meta: { title: '考勤申诉' }
      },
      {
        path: 'summary',
        component: () => import('@/views/attendance/summary'),
        name: 'Summary',
        meta: { title: '考勤汇总' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    hidden: true,
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '欢迎页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/uril',
    component: Layout,
    redirect: '/uril',
    name: 'Util',
    meta: {
      title: '公共管理',
      icon: 'leave1'
    },
    children: [
      {
        path: 'holidaylaws',
        component: () => import('@/views/attendance/holidaylaws'),
        name: 'Holidaylaws',
        meta: { title: '假期排班管理' }
      }
    ]
  },
  {
    path: '/leavemgr',
    component: Layout,
    redirect: '/leavemgr',
    name: 'LeaveMgr',
    meta: {
      title: '请假单管理',
      icon: 'leave1'
    },
    children: [
      {
        path: 'leave-all',
        component: () => import('@/views/attendance/leave'),
        name: 'leave-all',
        meta: { title: '请假单（全量）' }
      },
      {
        path: 'leave-dept',
        component: () => import('@/views/attendance/leave'),
        name: 'leave-dept',
        meta: { title: '请假单（部门）' }
      },
      {
        path: 'leave-person',
        component: () => import('@/views/attendance/leave'),
        name: 'leave-person',
        meta: { title: '请假单（个人）' }
      }
    ]
  },
  {
    path: '/travelmgr',
    component: Layout,
    redirect: '/travelmgr',
    name: 'TravelMgr',
    meta: {
      title: '因公外出管理',
      icon: 'guide'
    },
    children: [
      {
        path: 'travel-all',
        component: () => import('@/views/attendance/travel'),
        name: 'travel-all',
        meta: { title: '因事外出查询（全量）' }
      },
      {
        path: 'travel-dept',
        component: () => import('@/views/attendance/travel'),
        name: 'travel-dept',
        meta: { title: '因事外出查询（部门）' }
      },
      {
        path: 'travel-person',
        component: () => import('@/views/attendance/travel'),
        name: 'travel-person',
        meta: { title: '因事外出查询（个人）' }
      },
      {
        path: 'travel-change',
        component: () => import('@/views/attendance/travel-change'),
        name: 'Travel-Change',
        meta: { title: '变更因事外出申请单' }
      }
    ]
  },
  {
    path: '/approval',
    component: Layout,
    redirect: '/approval',
    name: 'Approval',
    meta: {
      title: '审批管理',
      icon: 'approve'
    },
    children: [
      {
        path: 'approval-travel',
        component: () => import('@/views/attendance/approval/approval-travel'),
        name: 'Approval-Travel',
        meta: { title: '出差申请单审批' }
      },
      {
        path: 'approval-appeal',
        component: () => import('@/views/attendance/approval/approval-appeal'),
        name: 'Approval-Appeal',
        meta: { title: '考勤申诉审批' }
      },
      {
        path: 'approval-leave',
        component: () => import('@/views/attendance/approval/approval-leave'),
        name: 'Approval-Leave',
        meta: { title: '请假单审批' }
      }
    ]
  }, {
    path: '/test',
    component: Layout,
    redirect: '/test',
    name: 'Test',
    meta: {
      title: '测试管理',
      icon: 'upload'
    },
    children: [
      {
        path: 'test-upload',
        component: () => import('@/views/attendance/components/fileupload'),
        name: 'Test-upload',
        meta: { title: '上传测试' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
